package org.zpmis.domain.order.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.zpmis.domain.order.model.OrderDetail;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
public class OrderDetailVo{
    /**
     * 明细id
     */
    private Long id;

    /**
     * 订单id
     */
    private Long orderId;

    /**
     * 明细编号
     */
    private String detailNum;

    /**
     * 收款金额
     */
    private BigDecimal collectionAmount;

    /**
     * 收款时间
     */
    private String collectionTime;

    /**
     * 收款人
     */
    private String collection;

    /**
     * 收款状态 0 未收款  1已收款
     */
    private Integer collectionStatus;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 修改时间
     */
    private String updateTime;

    /**
     * 明细备注
     */
    private String remark;

    /**
     * 是否删除
     */
    private Integer isDeleted;

    public OrderDetailVo(OrderDetail orderDetail) {
        this.id = orderDetail.getId();
        this.orderId = orderDetail.getOrderId();
        this.detailNum = orderDetail.getDetailNum();
        this.collectionAmount = orderDetail.getCollectionAmount();
        this.collectionTime = orderDetail.getCollectionTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(orderDetail.getCollectionTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.collection = orderDetail.getCollection();
        this.collectionStatus = orderDetail.getCollectionStatus();
        this.createTime = orderDetail.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(orderDetail.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.updateTime = orderDetail.getUpdateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(orderDetail.getUpdateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.remark = orderDetail.getRemark();
        this.isDeleted = orderDetail.getIsDeleted();
    }
}